package com.wontube.smr.remote.admin;

import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.core.annotation.NoLoginSupport;
import com.wontube.core.cache.Cacher;
import com.wontube.core.pub.servlet.handlers.BasicHandler;
import com.wontube.smr.dao.bo.FeedbackDao;
import com.wontube.smr.web.client.IFeedbackHandler;
import com.wontube.smr.web.client.admin.IAdminFeedbackHandler;
import com.wontube.smr.web.client.model.po.FeedbackReply;
import com.wontube.smr.web.client.model.vo.FeedbackItems;

/**
 * @author tanggf(2012-6-7)
 *
 */
@NoLoginSupport
public class AdminFeedbackHandler extends BasicHandler implements IAdminFeedbackHandler {

	@Override
	public FeedbackItems queryFeedbacks(Integer status, Integer feedType, PagenateInfo pageInfo) {
		return FeedbackDao.selectFeedbacks(pageInfo, status, feedType);
	}

	@Override
	public Integer replyFeedback(FeedbackReply reply) {
		int aff = FeedbackDao.addFeedbackReply(reply);
		if(aff > 0){			
			deleteAllFeedbackCaches();
		}
		return aff;
	}

	@Override
	public Integer deleteFeedbacks(String[] ids) {
		int aff = FeedbackDao.deleteFeedback(ids);
		if(aff > 0){			
			deleteAllFeedbackCaches();
		}
		return aff;
	}
	
	@Override
	public Integer undeleteFeedback(String id) {
		int aff =  FeedbackDao.undeleteFeedback(id);
		if(aff > 0){
			deleteAllFeedbackCaches();
		}
		return aff;
	}	

	@Override
	public Integer deleteFeedbackReply(String id) {
		int aff =  FeedbackDao.deleteFeedbackReply(id);
		if(aff > 0){
			deleteAllFeedbackCaches();
		}
		return aff;
	}	
	
	private void deleteAllFeedbackCaches(){
		String clazzName = IFeedbackHandler.class.getName();
		String methodName = "listFeedbacks";
		Cacher.defaultCacher.deleteAllCache(clazzName, methodName, 2);
	}
}
